package com.nowcoder.code.hjnc;

public class NC7 {


    public int maxProfit(int[] prices) {

        int r = prices[0];
        int res = 0;

        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > r) {
                res = Math.max(res, prices[i] - r);
            } else {
                r = prices[i];
            }
        }

        return res;
    }


}
